﻿#ifndef _WEB_PTHREAD_H_
#define _WEB_PTHREAD_H_


#include <pthread.h>

class web_pthread{
    public:
        web_pthread(){};
        virtual ~web_pthread(){};
        
    public:
        inline void start(pthread_attr_t *tattr = NULL){pthread_create(&ct_tID, tattr, ThreadFunc, this);}
        inline static void* ThreadFunc(void* pthreadOBJ){(static_cast<web_pthread*>(pthreadOBJ))->run();}
        inline pthread_t get_tid(){return ct_tID;}
        inline int join(void **retval = NULL){return pthread_join(ct_tID,retval);}
        inline int detach(){return pthread_detach(ct_tID);}
        // inline void Exit(void *retval = NULL){pthread_exit(retval);}
        inline virtual void cancel(){pthread_cancel(ct_tID);}
        
    private:
        virtual void run() = 0;
        
    private:
        pthread_t ct_tID;
};




#endif /*_WEB_PTHREAD_H*/


